package com.ql.design.flyweight;

import java.util.Hashtable;

//享元工厂(FlyweightFactory)角色
public class FlyweightFactory {
	//池容器
	private Hashtable flyweights = new Hashtable();// 定义hashtable 存储各对象

	public FlyweightFactory() {

	}
	// 从池中获取对象
	public Flyweight getFlyWeight(Object obj) {
		Flyweight flyweight = (Flyweight) flyweights.get(obj);
		if (flyweight == null) {// 
			flyweight = new ConcreteFlyweight((String) obj);// 产生新的ConcreteFlyweight
			flyweights.put(obj, flyweight);// 
		}
		return flyweight;// 
	}

	public int getFlyweightSize() {
		return flyweights.size();
	}

}
